package cn.admin.controller;

import cn.admin.config.key.StatusCode;
import cn.admin.service.InterestRateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 21:37 2019/4/18
 */
@RestController
@RequestMapping("/interest_rate")
public class InterestRateController {

    @Autowired
    private InterestRateService interestRateService;

    @RequestMapping("/modifyInterestRate")
    public String modifyInterestRate(@RequestParam("interest_rate") String interest_rate) {
        System.out.println(interest_rate);
        try {
            System.out.println(Double.valueOf(interest_rate));
            if (Double.valueOf(interest_rate) >= 0) {
                int i = interestRateService.modifyInterestRate(Double.valueOf(interest_rate));
                switch (i) {
                    case 0:
                        return StatusCode.STATUS_FAIL;  //fail
                    case 1:
                        return StatusCode.STATUS_SUCCESS;   //success
                    default:
                        return StatusCode.STATUS_FAIL;  //fail
                }
            } else {
                return StatusCode.STATUS_SMALL; //small
            }
        } catch (Exception e) {
            e.printStackTrace();
            return StatusCode.STATUS_ERROR; //error
        }
    }


}
